<%--
  Created by IntelliJ IDEA.
  User: Xuejun
  Date: 2024/12/2
  Time: 14:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="cn.gxj62.secelt" %>
<%@ page import="cn.gxj62.Student" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="cn.gxj62.mysql" %>
<html>
<head>
    <title>学生统计</title>
    <link rel="stylesheet" type="text/css" href="style/studentCard.css">
    <link rel="stylesheet" type="text/css" href="style/page.css">
</head>
<body>
<%
    Connection con = mysql.SQLConnect();
    ArrayList<Student> students = null;
    if (con != null) {
        students = mysql.getStudents(con);
    }

%>
<h1>学生统计</h1>
<a href="index.jsp">返回主页</a>
<h2>女同学数量</h2>
<p><%
    if (students != null) {
        out.print(secelt.getFemaleCount(students));
    } else {
        out.print("0");
    }
%></p>
<h2>男同学数量</h2>
<p><%
    if (students != null) {
        out.print(secelt.getMaleCount(students));
    } else {
        out.print("0");
    }
%></p>
<h2>年龄最大的学生</h2>
<%
    ArrayList<Student> maxAgeStudents = null;
    if (students != null) {
        maxAgeStudents = secelt.getMaxAgeStudents(students);
    }
%>
<div class="studentCard-container">
    <%
        if (maxAgeStudents != null) {
            for (Student student : maxAgeStudents) {
                out.println("<table class='studentCard'>");
                out.println("<tr>");
                out.println("<td>学号:</td><td>" + student.getId() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>姓名：</td><td>" + student.getName() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>年龄：</td><td>" + student.getAge() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>专业：</td><td>" + student.getMajor() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>性别：</td><td>" + (student.getSex() ? "男" : "女") + "</td>");
                out.println("</tr><tr>");
                out.println("<td>是否班干：</td><td>" + (student.isLeader() ? "是" : "否") + "</td>");
                out.println("</tr>");
                out.println("</table>");
            }
        }
    %>
</div>
<h2>年龄最小的学生</h2>
<%
    ArrayList<Student> minAgeStudents = null;
    if (students != null) {
        minAgeStudents = secelt.getMinAgeStudents(students);
    }
%>
<div class="studentCard-container">
    <%
        if (minAgeStudents != null) {
            for (Student student : minAgeStudents) {
                out.println("<table class='studentCard'>");
                out.println("<tr>");
                out.println("<td>学号:</td><td>" + student.getId() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>姓名：</td><td>" + student.getName() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>年龄：</td><td>" + student.getAge() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>专业：</td><td>" + student.getMajor() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>性别：</td><td>" + (student.getSex() ? "男" : "女") + "</td>");
                out.println("</tr><tr>");
                out.println("<td>是否班干：</td><td>" + (student.isLeader() ? "是" : "否") + "</td>");
                out.println("</tr>");
                out.println("</table>");
            }
        }
    %>
</div>
<h2>是班干部的同学</h2>
<%
    ArrayList<Student> leaderStudents = null;
    if (students != null) {
        leaderStudents = secelt.getLeaderStudents(students);
    }
%>
<div class="studentCard-container">
    <%
        if (leaderStudents != null) {
            for (Student student : leaderStudents) {
                out.println("<table class='studentCard'>");
                out.println("<tr>");
                out.println("<td>学号:</td><td>" + student.getId() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>姓名：</td><td>" + student.getName() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>年龄：</td><td>" + student.getAge() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>专业：</td><td>" + student.getMajor() + "</td>");
                out.println("</tr><tr>");
                out.println("<td>性别：</td><td>" + (student.getSex() ? "男" : "女") + "</td>");
                out.println("</tr><tr>");
                out.println("<td>是否班干：</td><td>" + (student.isLeader() ? "是" : "否") + "</td>");
                out.println("</tr>");
                out.println("</table>");
            }
        }
    %>
</div>
</body>
</html>
